#include "mainwindow.h"
#include "easylog.h"
#include <QApplication>
#include "modules/video_capture/video_capture.h"
#include "video_capturer_test.h"
#include <QString>
#include <QDebug>
#include <QMetaType>
#include <QStandardItemModel>
#include <Windows.h>
#include <QMainWindow>

#include "modules/video_capture/video_capture_factory.h"
#include "rtc_base/logging.h"
#include "video_capture.h"
#include "video_capturer_test.h"
#include "api/peer_connection_interface.h"
#include "api/create_peerconnection_factory.h"
#include "rtc_base/checks.h"
#include "rtc_base/ssl_adapter.h"
#include "rtc_base/win32_socket_init.h"
#include "rtc_base/win32_socket_server.h"

#include "absl/memory/memory.h"
#include "absl/types/optional.h"
#include "api/audio/audio_mixer.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_encoder_factory.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/audio_options.h"
#include "api/create_peerconnection_factory.h"
#include "api/rtp_sender_interface.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_processing/include/audio_processing.h"
#include "modules/video_capture/video_capture.h"
#include "modules/video_capture/video_capture_factory.h"
#include "p2p/base/port_allocator.h"
#include "pc/video_track_source.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "api/video/i420_buffer.h"
#include "signal_client.h"


#pragma comment (lib,"advapi32.lib")

extern"C"

BOOLEAN WINAPI SystemFunction036(PVOID, ULONG);

#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "secur32.lib")
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "dmoguids.lib")
#pragma comment(lib, "wmcodecdspuuid.lib")
#pragma comment(lib, "amstrmid.lib")
#pragma comment(lib, "msdmo.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "Gdi32.lib")






void InitCustomMetaType(){
    qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>");
    qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>&");
    qRegisterMetaType<webrtc::VideoTrackInterface*>("webrtc::VideoTrackInterface*");
    qRegisterMetaType<webrtc::MediaStreamTrackInterface*>("webrtc::MediaStreamTrackInterface*");
    qRegisterMetaType<uint8_t*>("uint8_t*");
    qRegisterMetaType<uint64_t>("uint64_t");
    qRegisterMetaType<uint32_t>("uint32_t");
}



int main(int argc, char *argv[])
{
    InitCustomMetaType();

    rtc::WinsockInitializer winsock_init;
    rtc::Win32SocketServer w32_ss;
    rtc::Win32Thread w32_thread(&w32_ss);
    rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
    rtc::InitializeSSL();

    setbuf(stdout, NULL);

    QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
    QApplication a(argc, argv);
    MainWindow w;
    w.setFixedSize(1024,768);
    w.setWindowTitle(QString("webrtc janus demo "));

    w.show();
    return a.exec();
}


